package pl.kosmowska.ewelina.client.app.activity.places;

import pl.kosmowska.ewelina.client.app.requestfactory.dto.InvestmentDataProxy;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.RequestFactory;

public class InvestmentEditPlace extends Place {
	  
	
	  @Prefix("DodajZmienLokate")
	  public static class Tokenizer implements PlaceTokenizer<InvestmentEditPlace> {

	    private RequestFactory requestFactory;
	    
	    public Tokenizer(RequestFactory requestFactory) {
	      this.requestFactory = requestFactory;
	    }
	    	    
	    @Override
	    public String getToken(InvestmentEditPlace place) {
	      String s = "";
	      if (place.getInvestmentDataId() != null) {
	        s = requestFactory.getHistoryToken(place.getInvestmentDataId());
	      } else if (place.getInvestmentData() != null) {
	        s = requestFactory.getHistoryToken(place.getInvestmentData().stableId());
	      } else {
	        s = "new"; 
	      }
	      return s;
	    }

	    /**
	     * from - url activated
	     */
	    @Override
	    public InvestmentEditPlace getPlace(String token) {
	      EntityProxyId<InvestmentDataProxy> InvestmentDataId = null;
	      if (token == null || token.trim().length() == 0 || token.equals("new") == true) {
	        // new
	      } else {
	        InvestmentDataId = requestFactory.<InvestmentDataProxy> getProxyId(token);
	      }
	      return new InvestmentEditPlace(InvestmentDataId);
	    }

	  }
	     
	  /**
	   * from app place move
	   */
	  private InvestmentDataProxy investmentData;
	  
	  /**
	   * from url place move
	   */
	  private EntityProxyId<InvestmentDataProxy> investmentDataId;
	  
	  /**
	   * constructor - from app new place
	   */
	  public InvestmentEditPlace() {
	    this.investmentDataId = null;
	    this.investmentData = null;
	  }

	  
	  
	  /**
	   * constructor - from app place move
	   * @param walletData
	   */
	  public InvestmentEditPlace(InvestmentDataProxy InvestmentData) {
	    this.investmentDataId = null;
	    this.investmentData = InvestmentData;
	  }

	  /**
	   * constructor - from url move
	   * @param walletDataId
	   */
	  public InvestmentEditPlace(EntityProxyId<InvestmentDataProxy> InvestmentDataId) {
	    this.investmentDataId = InvestmentDataId;
	  }
	  

	  public EntityProxyId<InvestmentDataProxy> getInvestmentDataId() {
		    return investmentDataId;
		  }
	  
	  public InvestmentDataProxy getInvestmentData() {
		    return investmentData;
		  }
	 
	}


